package com.heu.blood.analysis.controller;

import com.heu.blood.analysis.entity.BloodTestTransfusionEntity;
import com.heu.blood.analysis.service.BloodTestTransfusionService;
import com.heu.blood.analysis.vo.BloodTestAndChargeVo;
import com.heu.blood.analysis.vo.BloodTestqueryPatientTestResultVo;
import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 存在输血申请的血液检验表
 *
 * @author lhh
 * @email lhh1612325771@163.com
 * @date 2023-11-29 20:41:10
 */
@RestController
@RequestMapping("analysis/bloodtesttransfusion")
public class BloodTestTransfusionController {
    @Autowired
    private BloodTestTransfusionService bloodTestTransfusionService;


    /**
     * 分页联表条件查询病人血液样本和检测结果
     * @param params
     * @return
     */
    @RequestMapping("/selectBloodTestTransfusionPage")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "分页联表条件查询病人血液样本和检测结果")
    public R selectBloodTestTransfusionPage(@RequestParam Map<String, Object> params){
        PageUtils page = bloodTestTransfusionService.selectSamplePatientTestPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 分页联表查询输血申请的病人的输血申请单和检测结果
     * 即可以根据输血申请单的单号查询
     */
    @RequestMapping("/selectBloodTestTransfusionApplicationPage")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "分页联表查询输血申请的病人的输血申请单和检测结果")
    public R selectBloodTestTransfusionApplicationPage(@RequestParam Map<String, Object> params){
        PageUtils page = bloodTestTransfusionService.selectBloodTestTransfusionApplicationPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 查询存在输血申请病人样本检测报告
     * @param bloodSampleId
     * @return
     */
    @GetMapping("/queryPatientTestResult")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "根据BloodSampleId查询存在输血申请病人样本检测报告")
    public R queryPatientTestResult(String bloodSampleId){
        BloodTestqueryPatientTestResultVo resultVo = bloodTestTransfusionService.queryPatientTestResult(bloodSampleId);
        return R.ok().put("data", resultVo);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "根据id查询输血申请病人血液检测信息")
    public R info(@PathVariable("id") Integer id){
		BloodTestTransfusionEntity bloodTestTransfusion = bloodTestTransfusionService.getById(id);

        return R.ok().put("data", bloodTestTransfusion);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "保存输血申请病人血液检测信息")
    public R save(@RequestBody BloodTestAndChargeVo bloodTestAndChargeVo){
		int res = bloodTestTransfusionService.saveBatchWithCharge(bloodTestAndChargeVo);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "更新输血申请病人血液检测信息")
    public R update(@RequestBody List<BloodTestTransfusionEntity> bloodTestTransfusionEntityList){
		bloodTestTransfusionService.updateInspectResult(bloodTestTransfusionEntityList);
        return R.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "根据id删除输血申请病人血液检测信息")
    public R delete(@RequestBody Integer[] ids){
		bloodTestTransfusionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 根据样本id查询检验结果列表
     */
    @RequestMapping("/getTestResWithSampleId/{bloodSampleInfoTransfusionId}")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "根据样本id查询检验结果列表")
    public R getTestResWithSampleId(@PathVariable("bloodSampleInfoTransfusionId") String bloodSampleInfoTransfusionId){
        List<BloodTestTransfusionEntity> list = bloodTestTransfusionService.getTestResWithSampleId(bloodSampleInfoTransfusionId);
        return R.ok().put("data",list);
    }

    @RequestMapping("/checkReviewResult/{bloodSampleInfoTransfusionId}")
    @ControllerLogAnnotation(module = "存在输血申请的血液检验", operate = "判断是否已全部审核通过")
    public R checkReviewResult(@PathVariable("bloodSampleInfoTransfusionId") String bloodSampleInfoTransfusionId){
        int res= bloodTestTransfusionService.checkReviewResult(bloodSampleInfoTransfusionId);
        return R.ok();
    }

}
